<template>
	<view>
		<!-- 切换tab -->
		<view class="flexcenter mainpadding ffffff">
			<view class="flexcenter wushi">
				<view :class="current==1?'focustext':'nofocustext'" @click="selectab(1)">赛事报名</view>
			</view>
			<view class="flexcenter wushi">
				<view :class="current==2?'focustext':'nofocustext'" @click="selectab(2)">活动报名</view>
			</view>
		</view>
		<!-- 内容 -->
		<view class="mainpadding2 ffffff margin_top1">
			<view class="flexcenter" v-if="!list.data.length">
				<view class="placeholderimage" style="margin-top: 300rpx;" ></view>
			</view>
			<template v-if="current == 1">
				<view class="flexbetween  shangc" :class="index+1==list.total?'':'xiahuaxian'" v-for="(item,index) in list.data" :key="item.id" @click="tzssxq(1,item.id)">
					<view class="shilitu">
						<image :src="item.ss.image_text" mode=""></image>
					</view>
					<view class="" style="width: 69%;">
						<view class="flexleft">
							<!-- 1=未开始,2=报名中,3=待开赛,4=已开赛,5=赛事结束 -->
							<view class="xiaolhbtn margin_right1" v-if="item.ss.ss_status==1">未开始</view>
							<view class="xiaocbtn margin_right1" v-if="item.ss.ss_status==2">报名中</view>
							<view class="xiaolabtn margin_right1" v-if="item.ss.ss_status==3">待开赛</view>
							<view class="xiaojubtn margin_right1" v-if="item.ss.ss_status==4">已开赛</view>
							<view class="xiaohbtn margin_right1" v-if="item.ss.ss_status==5">赛事结束</view>
							<view class="titletext xiaohei fonweight yhxk">{{item.ss.name}}</view>
						</view>
						<view class="strongtext xiaohui nofonweight margin_right2 margin_top1">
							开始时间：{{item.ss.bm_starttime_text}}</view>
						<view class="strongtext xiaohui nofonweight margin_right2 margin_top1">
							截至时间：{{item.ss.bm_endtime_text}}</view>
						<view class="strongtext xiaohui nofonweight margin_right2 yhxk margin_top1">{{item.ss.cityinfo}}{{item.ss.address}}</view>
					</view>
				</view>
			</template>
			<template v-if="current == 2">
				<view class=" shangc ":class="index+1==list.total?'':'xiahuaxian'" v-for="(item,index) in list.data" :key="item.id" @click="tzssxq(2,item.id)">
					<view class="flexbetween">
						<view class="shilitu">
							<image :src="item.activity.image_text" mode=""></image>
						</view>
						<view class="" style="width: 69%;">
							<view class="flexleft">
								<view class="xiaolhbtn margin_right1" v-if="item.activity.activity_status==1">未开始</view>
								<view class="xiaocbtn margin_right1" v-if="item.activity.activity_status==2">报名中</view>
								<view class="xiaolabtn margin_right1" v-if="item.activity.activity_status==3">待开赛</view>
								<view class="xiaojubtn margin_right1" v-if="item.activity.activity_status==4">已开赛</view>
								<view class="xiaohbtn margin_right1" v-if="item.activity.activity_status==5">赛事结束</view>
								<view class="titletext xiaohei fonweight yhxk">{{item.activity.name}}</view>
							</view>
							<view class="strongtext xiaohui nofonweight margin_right2 margin_top1">开始时间：{{item.activity.bm_starttime_text}}</view>
							<view class="strongtext xiaohui nofonweight margin_right2 margin_top1">结束时间：{{item.activity.bm_endtime_text}}</view>
							<view class="strongtext xiaohui nofonweight margin_right2 yhxk margin_top1">{{item.activity.cityinfo}}{{item.activity.address}}</view>
						</view>
					</view>
					<view class="flexbetween margin_top2" v-if="item.activity.zbfapply || item.activity.activity_status==2">
						<view class="flexleft">
							<view class="touxiang margin_right">
								<image v-if="item.activity.zbfapply" :src="item.activity.zbfapply.logo_text" mode=""></image>
							</view>
							<view class="ershil xiaohei nofonweight "v-if="item.activity.zbfapply">{{item.activity.zbfapply.name}}</view>
						</view>
						<view class="xiaolv ershil nofonweight" v-if="item.activity.activity_status==2">
							正在报名：{{item.activity.bm_join_num}}/{{item.activity.join_num}}
						</view>
					</view>
				</view>
			</template>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				current: 1,
				page: 1,
				limit: 12,
				list: {
					data: []
				},
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			init(isPage, page) {
				let _this = this;
				let data = {
					page: page || 1,
					limit: _this.limit,
				}
				let url = '/api/user/ssBmIndex'
				if (this.current == 2) {
					url = '/api/user/activityBmIndex'
				}
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			// 跳转赛事详情
			tzssxq(type,id) {
				uni.navigateTo({
					url: '/pages_mypage/saishibaomingxx?type='+type+'&id=' + id
				})
			},
			selectab(i) {
				if (i == this.current) {
					return false
				}
				this.current = i
				this.list.data = []
				this.init()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.huisebtn {
		width: 140rpx;
		height: 56rpx;
		background: #F5F5F5;
		border-radius: 28rpx 28rpx 28rpx 28rpx;
		font-size: 26rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #777777;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.lvsebtn {
		width: 140rpx;
		height: 56rpx;
		background: #1BA95B;
		border-radius: 28rpx 28rpx 28rpx 28rpx;
		font-size: 26rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.xiaolabtn {
		width: 80rpx;
		height: 40rpx;
		background: #078CE6;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		font-size: 20rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.xiaohbtn {
		width: 100rpx;
		height: 40rpx;
		background: #BAC3D5;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		font-size: 20rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #091636;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.xiaolhbtn {
		width: 80rpx;
		height: 40rpx;
		background: #1BA95B;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		font-size: 20rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.xiaojubtn {
		width: 80rpx;
		height: 40rpx;
		background: #F8B900;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		font-size: 20rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.xiaocbtn {
		width: 80rpx;
		height: 40rpx;
		background: #F76222;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		font-size: 20rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.touxiang {
		width: 40rpx;
		height: 40rpx;
		border-radius: 50%;

		image {
			border-radius: 50%;
			width: 100%;
			height: 100%;
		}
	}

	.shangc1 {
		padding-top: 30rpx;
	}

	.shangc1:first-child {
		padding-top: 0rpx;
	}


	.shangc {
		padding-top: 30rpx;
	}

	.shilitu {
		width: 200rpx;
		height: 160rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	page {
		background: #F9F9F9;
	}

	.wushi {
		width: 50%;
	}

	.focustext {
		font-size: 30rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #1BA95B;
	}

	.nofocustext {
		font-size: 30rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #000000;
	}
</style>